// 导入mongoose模块
const mongoose=require('mongoose')
// 创建Promise对象
new Promise((resolve, reject) => {
    mongoose.connect('mongodb://127.0.0.1:27017/bilibili')
    mongoose.connection.once('open',()=>{
        resolve('connect success!!')
    })
    mongoose.connection.once('error',()=>{
        reject('connect error!!')
    })
}).then(value => {
    console.log(value)
    // 创建结构对象
    let bookSchema=new mongoose.Schema({
        name: String,
        author: String,
        price: Number,
        is_hot:Boolean,
        tags:Array,
        save_time:Date,
        test:mongoose.Schema.Types.Mixed//任意类型数据
    })
    // 创建模型对象
    let bookModel=mongoose.model('books',bookSchema)
    //读取数据库数据
    bookModel.find().then(value=>{//读取成功
        console.log(value)
    },reason=>{ //读取失败
        console.log(reason);
    });
},reason => {
    console.log(reason);
})